home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / ada / txt2dat.ada < prev    next >
Text File  |  1988-03-25  |  2KB  |  58 lines

  1. -- TXT2DAT.ADA   Ver. 1.00   25-MAR-1988
  2. -- Copyright 1988 John J. Herro
  3. -- Software Innovations Technology Corp.
  4. -- 1083 Mandarin Drive NE, Palm Bay, FL 32905-4706   (407)951-0233
  5. --
  6. -- After running DAT2TXT on a PC and transferring the resulting TUTOR.TXT
  7. -- file to another computer, compile and run this program on the other
  8. -- computer to create ADA-TUTR.DAT on that machine.
  9. --
  10. --
  11. with DIRECT_IO, TEXT_IO;
  12. procedure TXT2DAT is
  13.    subtype BLOCK_SUBTYPE is STRING(1 .. 64);
  14.    package RANDOM_IO is new DIRECT_IO(BLOCK_SUBTYPE);
  15.    TEXT_FILE  : TEXT_IO.FILE_TYPE;                           -- The input file.
  16.    DATA_FILE  : RANDOM_IO.FILE_TYPE;                        -- The output file.
  17.    OK         : BOOLEAN := TRUE;     -- True when both files open successfully.
  18.    INPUT      : STRING(1 .. 65);           -- Line of text read from TUTOR.TXT.
  19.    LEN        : INTEGER;                 -- Length of line read from TUTOR.TXT.
  20.    LEGAL_NOTE : constant STRING :=
  21.         " Copyright 1988 Software Innovations Technology Corp. ";
  22.                          -- LEGAL_NOTE isn't used by the program, but it causes
  23.                          -- the compiler to place this string in the .EXE file.
  24. begin
  25.    begin
  26.       TEXT_IO.OPEN(TEXT_FILE, MODE => TEXT_IO.IN_FILE, NAME => "TUTOR.TXT");
  27.    exception
  28.       when TEXT_IO.NAME_ERROR =>
  29.          TEXT_IO.PUT_LINE(
  30.               "I'm sorry.  The file TUTOR.TXT seems to be missing.");
  31.          OK := FALSE;
  32.    end;
  33.    begin
  34.       RANDOM_IO.CREATE(DATA_FILE, RANDOM_IO.OUT_FILE, NAME => "ADA-TUTR.DAT");
  35.    exception
  36.       when others =>
  37.          TEXT_IO.PUT_LINE("I'm sorry.  I can't seem to create ADA-TUTR.DAT.");
  38.          TEXT_IO.PUT_LINE("Perhaps that file already exists?");
  39.          OK := FALSE;
  40.    end;
  41.    if OK then
  42.       while not TEXT_IO.END_OF_FILE(TEXT_FILE) loop
  43.          TEXT_IO.GET_LINE(FILE => TEXT_FILE, ITEM => INPUT, LAST => LEN);
  44.          INPUT(LEN + 1 .. 64) := (others => ' ');
  45.               -- In case trailing blanks were lost when transferring TUTOR.TXT.
  46.          for I in 1 .. LEN loop
  47.             if INPUT(I) = '~' then
  48.                INPUT(I) := ASCII.CR;
  49.             elsif INPUT(I) = '^' then
  50.                INPUT(I) := ASCII.LF;
  51.             end if;
  52.          end loop;
  53.          RANDOM_IO.WRITE(DATA_FILE, ITEM => INPUT(1 .. 64));
  54.       end loop;
  55.       TEXT_IO.PUT_LINE("ADA-TUTR.DAT created.");
  56.    end if;
  57. end TXT2DAT;
  58.